﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using ComLib.Data;
using ComLib.Web.Modules.Profiles;
using ComLib.Web.Lib.Controllers;
using ComLib.Account;
using ComLib.Web.Lib.Models;

namespace ComLib.CMS.Controllers
{
    /// <summary>
    /// Controller for Dynamic Html content pages.
    /// </summary>
    [HandleError]
    public class ProfileController : EntityControllerAutomaticDataBinding<Profile>, IEntityController
    {
        /// <summary>
        /// Edits the entity based on the username.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <returns></returns>
        public ActionResult EditByName(string username)
        {
            //User user = ComLib.Account.User.Get(username);            
            Profile profile = Profile.Repository.First(Query<Profile>.New().Where( p => p.UserName).Is(username));
            if (profile == null) return View("Pages/NotFound");

            var model = new EntityFormViewModel<Profile>();
            BuildViewModel(model, profile, "ModelForm", true);
            return View(PageLocationForEdit, model);
        }
    }
}
